package cn.jc.springframework.beans.factory.support;

import cn.jc.springframework.beans.BeansException;
import cn.jc.springframework.beans.factory.BeanFactory;
import cn.jc.springframework.beans.factory.config.BeanDefinition;

/**
 * @Description:
 * @author: JC
 * @date: 2022/5/30 18:14
 */
public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {

    public Object getBean(String name) {
        Object singleton = getSingleton(name);
        if(singleton != null){
            return singleton;
        }
        BeanDefinition beanDefinition = getDefinition(name);
        return createBean(name,beanDefinition);
    }

    protected abstract Object createBean (String name, BeanDefinition beanDefinition) throws BeansException;

    protected abstract BeanDefinition getDefinition(String beanName);
}
